//
//  WATFHomeSpeedView.swift
//  WiFiFaster
//
//  Created by one on 2023/12/28.
//

import UIKit

class WATFHomeSpeedView: UIView {
    
    override init(frame: CGRect) {
        
        super.init(frame: frame)
        addSubview(watf_ftvAnimateView)
        addSubview(watf_iconView)
//        addSubview(watf_ftvBgView)
//        watf_ftvBgView.addSubview(watf_ftvAnimateView)
//        watf_ftvBgView.addSubview(watf_ftvIconView)
        addSubview(watf_smartView)
       
        watf_iconView.snp.makeConstraints { make in
            make.size.equalTo(CGSize(width: 206, height: 192))
            make.centerX.equalToSuperview()
            make.top.equalTo(watf_smartView.snp.bottom).offset(20)
        }
       
//        watf_ftvBgView.snp.makeConstraints { make in
//            make.edges.equalTo(watf_iconView)
//        }
//        watf_ftvIconView.snp.makeConstraints { make in
//            make.centerY.centerX.equalToSuperview()
//            make.size.equalTo(79)
//        }
        watf_ftvAnimateView.snp.makeConstraints { make in
            make.centerX.centerY.equalTo(watf_iconView)
            
            make.size.equalTo(CGSize(width: 206, height: 192))
        }
        watf_smartView.snp.makeConstraints { make in
            make.size.equalTo(CGSize(width: 308, height: 49))
            make.centerX.equalToSuperview()
            make.top.equalToSuperview().offset(10)
        }
        backgroundColor = WATFCommon.watf_getHXColorValue(rgb: 0x252525)
        layer.borderColor = WATFCommon.watf_getHXColorValue(rgb: 0x4E4E4E).cgColor
        layer.borderWidth = 1
        layer.cornerRadius = 16
        watf_updateStateView()
      
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    func watf_updateStateView() {
        //        guard let watf_funcModel = watf_funcModel else { return  }
        //        watf_iconView.image = UIImage(named: watf_funcModel.watf_complete ? "watf_home_icon2" : "watf_home_icon1" )
    }
    @objc func watf_speedClick() {
       
    }
    @objc func watf_smartClick() {
        watf_viewGetVController?.navigationController?.pushViewController(WATFFTVListViewController(), animated: true)
    }
    @objc func watf_ftvStateView() {
        
        if WATFManager.watf_manager.watf_ftvCurStateType == .watf_connected && !WATFManager.watf_manager.watf_ftvWork{
            watf_ftvAnimateView.isHidden = true
            watf_iconView.image = UIImage(named: "watf_home_icon2")
            watf_iconView.isUserInteractionEnabled = true
        }
        if WATFManager.watf_manager.watf_ftvCurStateType == .watf_connecting {
            watf_ftvAnimateView.isHidden = false
            watf_iconView.image = UIImage(named: "watf_ftv_normal")
            watf_iconView.isUserInteractionEnabled = false
        }
        if WATFManager.watf_manager.watf_ftvCurStateType == .watf_disconnecting {
            watf_ftvAnimateView.isHidden = false
            watf_iconView.image = UIImage(named: "watf_ftv_normal")
            watf_iconView.isUserInteractionEnabled = false
        }
        if WATFManager.watf_manager.watf_ftvCurStateType == .watf_disconnected && !WATFManager.watf_manager.watf_ftvWork{
            watf_ftvAnimateView.isHidden = true
            watf_iconView.image = UIImage(named: "watf_ftv_normal")
            watf_iconView.isUserInteractionEnabled = true
        }
        if WATFManager.watf_manager.watf_ftvCurStateType == .watf_invalid {
            watf_iconView.isUserInteractionEnabled = true
            watf_ftvAnimateView.isHidden = true
            watf_iconView.image = UIImage(named: "watf_ftv_normal")
            
        }
    }
    // MARK: - watf lazy
    //    var watf_funcModel = WATFManager.watf_manager.watf_funcModels.first
    lazy var watf_iconView: UIImageView = {
        let watf_iconView = UIImageView(image: UIImage(named: "watf_ftv_normal"))
        return watf_iconView
    }()
//    lazy var watf_ftvBgView: UIImageView = {
//        let watf_ftvBgView = UIImageView(image: UIImage(named: "watf_home_animatebg"))
//        return watf_ftvBgView
//    }()
//    lazy var watf_ftvIconView: UIImageView = {
//        let watf_iconView = UIImageView(image: UIImage(named: "watf_home_animateIcon"))
//
//        return watf_iconView
//    }()
    lazy var watf_ftvAnimateView: UIImageView = {
        let watf_ftvAnimateView = UIImageView(image: UIImage(named: "watf_scan_animate"))
        watf_ftvAnimateView.layer.add(watf_scanKey, forKey: "watf_ftvAnimateView")
        return watf_ftvAnimateView
    }()
    lazy var watf_scanKey: CABasicAnimation = {
        let watf_scanKey = CABasicAnimation.init(keyPath: "transform.rotation")
        watf_scanKey.fromValue = NSNumber.init(value: 0)
        watf_scanKey.toValue = NSNumber.init(value: Double.pi*2)
        watf_scanKey.duration = 1
        watf_scanKey.repeatCount = MAXFLOAT
        watf_scanKey.isRemovedOnCompletion = false
        return watf_scanKey
    }()
    lazy var watf_smartView: UIImageView = {
        let watf_smartView = UIImageView(image: UIImage(named: "watf_home_smart"))
        watf_smartView.watf_addTap(target: self, action: #selector(watf_smartClick))
        return watf_smartView
    }()
   
}
